#The TSP problem
#created by Logan Rooper/Quinn Millegan - Riverdale High School - logan.rooper@gmail.com
#Hill Climber
#JusticeForAaronSwartz
import random
import math

################################################################################################
cycles = int(input("How many iterations do you want? >")) #INCREASE THIS TO INCREASE ITERATIONS#
num_cities = int(input("How many cities do you want? >")) #SET NUMBER OF CITIES                 #
################################################################################################

#Setting up the problem
print("Setting up the problem")
cities=[] #the regular city map
h_cities=[] #the highscore city map

#Generate num_cities random cities
#Cities should be in a X by Y array (0-9 coordinates
#Coordinates can be 101 through 199 (1 is the octal padding bit)
print("There are "+str(len(cities))+" cities.")
citiesX=(random.sample(range(0,9),num_cities))
citiesY=(random.sample(range(0,9),num_cities))
print(str(citiesX))
print(str(citiesY))
for i in (range(0,num_cities)):
    print("City "+str(i+1)+" is X: "+str(citiesX[i])+" Y: "+str(citiesY[i]))
'''
cities=(random.sample(range(100,199), num_cities))
for x in range(0,num_cities):
    print("Making city "+str(x)+".")
    print("City "+str(x)+" is X: "+str(cities[x])[1]+" and Y:"+str(cities[x])[2])
'''
print("There are now "+str(num_cities)+" cities.")
#draw city map
'''
print("PRINT MAP")

#iterate through all coordinates

row = ""
count = 1
for z in range(100,199):
    if z in cities:
        row += "--*--|"
    else:
        row += "-----|"
    if count == 10:                #rows is the width of the map...unsused because of our integer data limits
        row += "\n"
        count = 0
    count += 1

print(row)
  '''      

print("Ready to create and run the Hill Climber algorithm??")
i = input(">")

#Create and run the algorithm
print("Creating/running the algorithm.")
high = 10000000.0 #arbitrarily high float value
done = False
i = 0
while (done != True):
    print("Finding first path "+str(i))
    helpnum=random.randint(0,num_cities-1)
    print(str(helpnum))
    p1x=citiesX[helpnum]
    p1y=citiesY[helpnum]
    print(str(p1x))
    print(str(p1y))
    #x2=citiesX[]
    x1=p1x
    #y2=citiesY[]
    y1=p1y
    for x in range(0,num_cities-1):
        maybe = math.sqrt(abs(int(citiesX[x])-int(x1))**2+abs(int(citiesY[x])-int(y1))**2)
        print(str(maybe))
        if maybe <= high:
            high = maybe
            print("High is "+str(high))
            p1x = citiesX[x]
            p1y = citiesY[x]
        
        
print()
print("Shortest path found was "+str(high)+" units long.")
'''
print("PRINT MAP") #map of h_cities
row = ""
count = 1
for z in range(100,199):
    if z in h_cities:
        if cities.index(z) < 10:
            cit = "0"+str(cities.index(z))
        else:
            cit = str(cities.index(z))
        row += "--"+cit+"-|"
    else:
        row += "-----|"
    if count == 10:
        row += "\n"
        count = 0
    count += 1

print(row)
'''
#EOF

